home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / sys / dir.h < prev    next >
C/C++ Source or Header  |  1990-09-18  |  3KB  |  88 lines

  1. /*
  2.  * Copyright (c) 1982, 1986 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)dir.h    7.2 (Berkeley) 12/22/86
  7.  */
  8.  
  9. #ifndef _DIR
  10. #define _DIR
  11.  
  12. #include <sys/types.h>
  13.  
  14. /*
  15.  * A directory consists of some number of blocks of DIRBLKSIZ
  16.  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
  17.  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
  18.  *
  19.  * Each DIRBLKSIZ byte block contains some number of directory entry
  20.  * structures, which are of variable length.  Each directory entry has
  21.  * a struct direct at the front of it, containing its inode number,
  22.  * the length of the entry, and the length of the name contained in
  23.  * the entry.  These are followed by the name padded to a 4 byte boundary
  24.  * with null bytes.  All names are guaranteed null terminated.
  25.  * The maximum length of a name in a directory is MAXNAMLEN.
  26.  *
  27.  * The macro DIRSIZ(dp) gives the amount of space required to represent
  28.  * a directory entry.  Free space in a directory is represented by
  29.  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
  30.  * in a directory block are claimed by the directory entries.  This
  31.  * usually results in the last entry in a directory having a large
  32.  * dp->d_reclen.  When entries are deleted from a directory, the
  33.  * space is returned to the previous entry in the same directory
  34.  * block by increasing its dp->d_reclen.  If the first entry of
  35.  * a directory block is free, then its dp->d_ino is set to 0.
  36.  * Entries other than the first in a directory do not normally have
  37.  * dp->d_ino set to 0.
  38.  */
  39. /* so user programs can just include dir.h */
  40. #if !defined(KERNEL) && !defined(DEV_BSIZE)
  41. #define    DEV_BSIZE    512
  42. #endif
  43. #define DIRBLKSIZ    DEV_BSIZE
  44. #define    MAXNAMLEN    255
  45.  
  46. struct    direct {
  47.     u_long    d_ino;            /* inode number of entry */
  48.     u_short    d_reclen;        /* length of this record */
  49.     u_short    d_namlen;        /* length of string in d_name */
  50.     char    d_name[MAXNAMLEN + 1];    /* name must be no longer than this */
  51. };
  52.  
  53. /*
  54.  * The DIRSIZ macro gives the minimum record length which will hold
  55.  * the directory entry.  This requires the amount of space in struct direct
  56.  * without the d_name field, plus enough space for the name with a terminating
  57.  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  58.  */
  59. #undef DIRSIZ
  60. #define DIRSIZ(dp) \
  61.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  62.  
  63. #ifndef KERNEL
  64. /*
  65.  * Definitions for library routines operating on directories.
  66.  */
  67. typedef struct _dirdesc {
  68.     int    dd_fd;
  69.     long    dd_loc;
  70.     long    dd_size;
  71.     char    dd_buf[DIRBLKSIZ];
  72. } DIR;
  73.  
  74. #define dirfd(dirp)    ((dirp)->dd_fd)
  75.  
  76. #ifndef NULL
  77. #define NULL 0
  78. #endif
  79. extern    DIR *opendir();
  80. extern    struct direct *readdir();
  81. extern    long telldir();
  82. extern    void seekdir();
  83. #define rewinddir(dirp)    seekdir((dirp), (long)0)
  84. extern    void closedir();
  85. #endif
  86.  
  87. #endif /* _DIR */
  88.